// account-security.js
import { isLoggedIn, getUserInfo as getLocalUserInfo } from '../../../utils/http';

Page({
  data: {
    userInfo: {},
    maskedPhone: ''
  },

  onLoad() {
    // 设置导航栏标题
    wx.setNavigationBarTitle({
      title: '账户安全'
    });
    
    // 获取用户信息
    this.loadUserInfo();
  },

  onShow() {
    // 页面显示时重新加载用户信息
    this.loadUserInfo();
  },

  // 加载用户信息
  loadUserInfo() {
    if (isLoggedIn()) {
      const userInfo = getLocalUserInfo();
      
      // 创建手机号码掩码
      let maskedPhone = '';
      if (userInfo.phone) {
        maskedPhone = userInfo.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
      }
      
      this.setData({
        userInfo: userInfo,
        maskedPhone: maskedPhone
      });
    } else {
      // 如果未登录，返回登录页
      wx.navigateTo({
        url: '/pages/login/login'
      });
    }
  },

  // 导航到修改密码页
  navigateToChangePassword() {
    wx.navigateTo({
      url: '/pages/profile/change-password/change-password'
    });
  }
}) 